/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Student.java
 *
 * Created on May 4, 2011, 2:12:26 AM
 */

package c0907m.group2.aitsm.gui;

import c0907m.group2.aitsm.core.db.ClassDb;
import c0907m.group2.aitsm.core.db.CourseDb;
import c0907m.group2.aitsm.core.db.CourseYearDb;
import c0907m.group2.aitsm.core.db.StudentDb;
import c0907m.group2.aitsm.core.entity.ClassInfo;
import c0907m.group2.aitsm.core.entity.CourseInfo;
import c0907m.group2.aitsm.core.entity.CourseYearInfo;
import c0907m.group2.aitsm.core.entity.StudentInfo;
import c0907m.group2.aitsm.core.report.StudentReporter;
import c0907m.group2.aitsm.gui.component.DefaultPanel;
import c0907m.group2.aitsm.gui.component.StatusBar;
import c0907m.group2.aitsm.gui.handler.TableCellListener;
import c0907m.group2.aitsm.util.DateSynchronizer;
import c0907m.group2.aitsm.util.Helper;
import c0907m.group2.aitsm.util.Settings;
import com.standbysoft.component.date.swing.JDatePicker;
import com.standbysoft.component.date.swing.plaf.basic.SpinnerTimePickerUI;
import net.sf.jasperreports.engine.JRException;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import java.awt.event.ActionEvent;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author ISTC
 */
public class Student extends DefaultPanel {
    //default state on status bar when init
    public static final String DEFAULT_STATUS = "Add, update, delete students";
    public final Logger logger = Logger.getLogger(Student.class.getName());
    private DefaultTableModel dtm;
    private StatusBar statusBar;
    private List<StudentInfo> editingList;
    private List<ClassInfo> allClasses;
    private StudentDb studentDB;
    private ClassDb classDb;
    private DefaultCellEditor classEditor;
    private JComboBox cboClassTable;
    private List<CourseInfo> allCourses;
    private List<CourseYearInfo> allCourseYears;
    private List<Integer> classIDs;

    public void setStatusBar(StatusBar sb) {
        this.statusBar = sb;
    }

    public JButton getBtnAdd() {
        return btnAdd;
    }

    public JButton getBtnUpdate() {
        return btnUpdate;
    }

    /**
     * Creates new form Student
     */
    public Student() {
        initComponents();
        pnToggle.setVisible(false);
        btnUpdate.setEnabled(false);
        statusBar = new StatusBar();
        studentDB = new StudentDb();
        editingList = new ArrayList<StudentInfo>();
        dtm = (DefaultTableModel) tblStudentList.getModel();
        cboClassTable = new JComboBox();
        loadDataToComboBox();
        loadStudentsToTable();
        tblStudentListEventHandler();
    }


    /**
     * Reload all data from database
     */
    @Override
    public void refresh() {
        dtm.setRowCount(0);
        doReset();
        loadStudentsToTable();
    }

    /**
     * Update changes
     */
    @Override
    public void doUpdate() {
        if (editingList.size() == 0) {
            statusBar.setMessage("No changes have been made: Update cancelled.", StatusBar.WARNING_TYPE);
            return;
        }

        try {
            studentDB.update(editingList);
            statusBar.setMessage("Update successful.", StatusBar.MESSAGE_TYPE);
        } catch (SQLException e) {
            logger.log(Level.WARNING, "Update failed: " + e.getMessage());
            statusBar.setMessage("Update failed.", StatusBar.ERROR_TYPE);
            refresh();
        }

        editingList.removeAll(editingList);
    }

    /**
     * Add new Student to database
     */
    @Override
    public void doAdd() {
        if (txtName.getText().trim().equals("")) {

			JOptionPane.showMessageDialog(
                    this,
                    "Name is required.",
                    "Message",
                    JOptionPane.ERROR_MESSAGE
            );

        } else {
            StudentInfo newStudent = new StudentInfo();

            String month = Helper.parsePattern("" + (cboMonth.getSelectedIndex() + 1));
            String day = Helper.parsePattern("" + cboDay.getSelectedItem());
            String year = "" + cboYear.getSelectedItem();

            long date = Helper.toDate(month + "-" + day + "-" + year).getTime();
            int classId = allClasses
                    .get(cboClass.getSelectedIndex())
                    .getId();

            newStudent.setName(txtName.getText().trim());
            newStudent.setBirthday(new java.sql.Date(date));
            newStudent.setClassId(classId);
            newStudent.setDescription(txaDescription.getText().trim());
            newStudent.setMale(rdoMale.isSelected());
            newStudent.setActive(true);

            try {
                studentDB.insert(newStudent);
                statusBar.setMessage("Student added", StatusBar.MESSAGE_TYPE);
//                dtm.addRow(new Object[] {newStudent.getId(),
//                                    newStudent.getName(),
//                                    newStudent.getDescription(),
//                                    newStudent.isActive()});
                refresh();
            } catch (SQLException ex) {
                logger.log(Level.SEVERE, ex.getMessage());
                statusBar.setMessage("Adding failed.", StatusBar.ERROR_TYPE);
            }

        }
    }

    /**
     * Reset all fields to blank
     */
    @Override
    public void doReset() {
        txtName.setText("");
        txaDescription.setText("");
        txtSearchByName.setText("");
        txtAdvName.setText("");
        rdoMale.setSelected(true);
    }

    /**
     * Search by name
     */
    public void nameSearch() {
        dtm = (DefaultTableModel) tblStudentList.getModel();
        dtm.setRowCount(0);

        String name = txtSearchByName.getText();
        List<StudentInfo> result;

        try {
            result = studentDB.select(name);
            if (result.size() != 0) {
                statusBar.setMessage(result.size() + " match(es) found.", StatusBar.MESSAGE_TYPE);

                dtm.setRowCount(0);
                addDataToTable(result);
            } else {
                statusBar.setMessage("No match found.", StatusBar.MESSAGE_TYPE);
            }
        } catch (SQLException e) {
            logger.log(Level.WARNING, e.getMessage());
            statusBar.setMessage("Search stopped.", StatusBar.ERROR_TYPE);
        }
    }

    private void advanceSearch() {
        dtm = (DefaultTableModel) tblStudentList.getModel();
        dtm.setRowCount(0);

        String name = txtAdvName.getText();
        int classId = 0;
        try {
            classId = new ClassDb().select()
                    .get(cboClassSearch.getSelectedIndex())
                    .getId();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        List<StudentInfo> result;

        try {
            result = studentDB.select(name, classId);
            if (result.size() != 0) {
                statusBar.setMessage(result.size() + " match(es) found.", StatusBar.MESSAGE_TYPE);

                addDataToTable(result);
            } else {
                statusBar.setMessage("No match found.", StatusBar.MESSAGE_TYPE);
            }
        } catch (SQLException e) {
            logger.log(Level.WARNING, e.getMessage());
            statusBar.setMessage("Search stopped.", StatusBar.ERROR_TYPE);
        }
    }

    /**
     * Load all Students from database to table when initialize
     */
    private void loadStudentsToTable() {
        classEditor = Helper.addComboBoxToTable(tblStudentList, cboClassTable, 3);
        JDatePicker datePicker = new JDatePicker();
        datePicker.putClientProperty("JDatePicker.TimePickerUI", SpinnerTimePickerUI.class.getName());
        datePicker.putClientProperty("JDatePicker.showTimePicker", Boolean.TRUE);
        datePicker.setEditable(true);
        datePicker.setDateFormat("MM/dd/yy hh:mm a");
        tblStudentList.setDefaultEditor(java.util.Date.class, JDatePicker.createTableCellEditor(datePicker));

        studentDB = new StudentDb();
        List<StudentInfo> studentList = null;
        try {
            studentList = studentDB.select();
        } catch (SQLException ex) {
            logger.log(Level.SEVERE, ex.getMessage());
            statusBar.setMessage("Unable to load data.", StatusBar.WARNING_TYPE);
        }

        dtm = (DefaultTableModel) tblStudentList.getModel();
        addDataToTable(studentList);
    }

    /**
     * Add data from a list of students into table
     *
     * @param result list to add
     */
    private void addDataToTable(List<StudentInfo> result) {
        classDb = new ClassDb();
        classIDs = new ArrayList<Integer>();
        try {
            for (StudentInfo r : result) {
                String className = classDb.select(r.getClassId()).getName();
                cboClassTable = (JComboBox) classEditor.getComponent();
                cboClassTable.setSelectedItem(className);
                dtm.addRow(new Object[]{
                        r.getId(),
                        r.getName(),
                        r.getBirthday(),
                        //classEditor.getCellEditorValue(),
                        className,
                        r.getDescription(),
                        r.isMale(),
                        r.isActive()});
                classIDs.add(r.getClassId());
            }
        } catch (SQLException ex) {
            logger.log(Level.SEVERE, null, ex.getSQLState());
            statusBar.setMessage("Unable to load data", StatusBar.ERROR_TYPE);
        }
    }

    /**
     * Load all data to all combobox that is used in this form
     */
    private void loadDataToComboBox() {
        new DateSynchronizer(cboDay, cboMonth, cboYear, 0, 50);

        try {
            allClasses = new ClassDb().select();
            allCourses = new CourseDb().select();
            allCourseYears = new CourseYearDb().select();
            List<ClassInfo> activeClass = new ArrayList<ClassInfo>();
            List<CourseInfo> activeCourse = new ArrayList<CourseInfo>();


            for (ClassInfo ci : allClasses) {
                if (ci.isActive()) {

                    cboClassReport.addItem(ci.getName());
                    cboClass.addItem(ci.getName());
                    cboClassTable.addItem(ci.getName());
                    activeClass.add(ci);
                }
                cboClassSearch.addItem(ci.getName());
            }
            allClasses = activeClass;

            for (CourseInfo ci : allCourses) {
                if (ci.isActive()) {
                    cboCourseReport.addItem(ci.getName());
                    activeCourse.add(ci);
                }
            }
            allCourses = activeCourse;

            for (CourseYearInfo cyi : allCourseYears) {
                cboCourseYearReport.addItem(cyi.getStartYear() + " - " + cyi.getEndYear());
            }

        } catch (SQLException ex) {
            logger.log(Level.SEVERE, ex.getSQLState());
            statusBar.setMessage("Unable to load data.", StatusBar.ERROR_TYPE);
        }
    }

    private void tblStudentListEventHandler() {
        tblStudentListCellHandler();
        tblStudentListRowSorter();
    }

    public void tblStudentListCellHandler() {
        Action action = new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                btnUpdate.setEnabled(true);
                TableCellListener tcl = (TableCellListener) e.getSource();

                int row = tcl.getRow();
                int column = tcl.getColumn();
                StudentInfo studentToUpdate = new StudentInfo();
                Date birthDay = (Date) dtm.getValueAt(row, 2);

                try {
                    cboClassTable = (JComboBox) classEditor.getComponent();

                    studentToUpdate.setId((Integer) dtm.getValueAt(row, 0));
                    studentToUpdate.setName((String) dtm.getValueAt(row, 1));
                    studentToUpdate.setBirthday(
                            new java.sql.Date(
                                    birthDay.getTime())
                    );
                    if (column==3)
                        studentToUpdate.setClassId(
                                allClasses.get(cboClassTable.getSelectedIndex())
                                        .getId()
                        );
                    else
                        studentToUpdate.setClassId(classIDs.get(row));
                    studentToUpdate.setDescription((String) dtm.getValueAt(row, 4));
                    studentToUpdate.setMale((Boolean) dtm.getValueAt(row, 5));
                    studentToUpdate.setActive((Boolean) dtm.getValueAt(row, 6));

                    editingList.add(studentToUpdate);
                } catch (NumberFormatException e1) {
                    JOptionPane.showMessageDialog(
                            null,
                            "Wrong format!",
                            "Warning",
                            JOptionPane.ERROR_MESSAGE
                    );
                    dtm.setValueAt(tcl.getOldValue(), row, column);
                } catch (Exception e2) {
                    logger.log(Level.SEVERE, null, e2);
                    statusBar.setMessage("Unknown", StatusBar.ERROR_TYPE);
                }

                //System.out.println("Event fired!");
            }
        };

        TableCellListener tcl = new TableCellListener(tblStudentList, action);
    }

    public void tblStudentListRowSorter() {
        RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(dtm);
        tblStudentList.setRowSorter(sorter);
    }

    /**
     * This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        dlgReport = new javax.swing.JDialog();
        pnReport = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        btnToggleClass = new javax.swing.JButton();
        btnToggleCourse = new javax.swing.JButton();
        pnToggleClass = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        cboClassReport = new javax.swing.JComboBox();
        btnViewClass = new javax.swing.JButton();
        pnToggleCourse = new javax.swing.JPanel();
        cboCourseReport = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        btnViewCourse = new javax.swing.JButton();
        btnToggleCourseYear = new javax.swing.JButton();
        pnToggleCourseYear = new javax.swing.JPanel();
        cboCourseYearReport = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        btnViewCourseYear = new javax.swing.JButton();
        btnAdd = new javax.swing.JButton();
        btnUpdate = new javax.swing.JButton();
        btnReport = new javax.swing.JButton();
        btnRefresh = new javax.swing.JButton();
        pnStudentList = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblStudentList = new javax.swing.JTable();
        jLabel4 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        txtSearchByName = new javax.swing.JTextField();
        btnSearchByName = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        btnDropDown = new javax.swing.JButton();
        pnToggle = new javax.swing.JPanel();
        txtAdvName = new javax.swing.JTextField();
        btnAdvSearch = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        cboClassSearch = new javax.swing.JComboBox();
        pnStudentInfo = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txaDescription = new javax.swing.JTextArea();
        txtName = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        cboMonth = new javax.swing.JComboBox();
        cboDay = new javax.swing.JComboBox();
        cboYear = new javax.swing.JComboBox();
        cboClass = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        rdoMale = new javax.swing.JRadioButton();
        rdoFemale = new javax.swing.JRadioButton();
        buttonGroup1.add(rdoMale);
        buttonGroup1.add(rdoFemale);

        dlgReport.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        pnReport.setBackground(new java.awt.Color(255, 255, 255));

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel11.setText("Report options");

        btnToggleClass.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/dropDown_btn.png"));
        btnToggleClass.setText("Report all students in a single class");
        btnToggleClass.setContentAreaFilled(false);
        btnToggleClass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToggleClassActionPerformed(evt);
            }
        });

        btnToggleCourse.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/dropDown_btn.png"));
        btnToggleCourse.setText("Report all students of a specific course");
        btnToggleCourse.setContentAreaFilled(false);
        btnToggleCourse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToggleCourseActionPerformed(evt);
            }
        });

        pnToggleClass.setBackground(new java.awt.Color(255, 255, 255));

        jLabel12.setFont(new java.awt.Font("Tahoma", 2, 11));
        jLabel12.setText("Choose a class:");

        btnViewClass.setText("View report");
        btnViewClass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnViewClassActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnToggleClassLayout = new javax.swing.GroupLayout(pnToggleClass);
        pnToggleClass.setLayout(pnToggleClassLayout);
        pnToggleClassLayout.setHorizontalGroup(
                pnToggleClassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnToggleClassLayout.createSequentialGroup()
                                .addGroup(pnToggleClassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(pnToggleClassLayout.createSequentialGroup()
                                                .addContainerGap()
                                                .addComponent(jLabel12))
                                        .addGroup(pnToggleClassLayout.createSequentialGroup()
                                                .addGap(47, 47, 47)
                                                .addComponent(cboClassReport, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(btnViewClass)))
                                .addContainerGap(51, Short.MAX_VALUE))
        );
        pnToggleClassLayout.setVerticalGroup(
                pnToggleClassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnToggleClassLayout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(pnToggleClassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(cboClassReport, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(btnViewClass))
                                .addContainerGap(49, Short.MAX_VALUE))
        );

        pnToggleCourse.setBackground(new java.awt.Color(255, 255, 255));

        jLabel13.setFont(new java.awt.Font("Tahoma", 2, 11));
        jLabel13.setText("Choose a course:");

        btnViewCourse.setText("View report");
        btnViewCourse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnViewCourseActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnToggleCourseLayout = new javax.swing.GroupLayout(pnToggleCourse);
        pnToggleCourse.setLayout(pnToggleCourseLayout);
        pnToggleCourseLayout.setHorizontalGroup(
                pnToggleCourseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGap(0, 308, Short.MAX_VALUE)
                        .addGroup(pnToggleCourseLayout.createSequentialGroup()
                                .addGroup(pnToggleCourseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(pnToggleCourseLayout.createSequentialGroup()
                                                .addContainerGap()
                                                .addComponent(jLabel13))
                                        .addGroup(pnToggleCourseLayout.createSequentialGroup()
                                                .addGap(47, 47, 47)
                                                .addComponent(cboCourseReport, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(btnViewCourse)))
                                .addContainerGap(51, Short.MAX_VALUE))
        );
        pnToggleCourseLayout.setVerticalGroup(
                pnToggleCourseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGap(0, 103, Short.MAX_VALUE)
                        .addGroup(pnToggleCourseLayout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel13)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(pnToggleCourseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(cboCourseReport, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(btnViewCourse))
                                .addContainerGap(49, Short.MAX_VALUE))
        );

        btnToggleCourseYear.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/dropDown_btn.png"));
        btnToggleCourseYear.setText("Report all students in a specific course-year:");
        btnToggleCourseYear.setContentAreaFilled(false);
        btnToggleCourseYear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToggleCourseYearActionPerformed(evt);
            }
        });

        pnToggleCourseYear.setBackground(new java.awt.Color(255, 255, 255));

        jLabel14.setFont(new java.awt.Font("Tahoma", 2, 11));
        jLabel14.setText("Choose a course-year:");

        btnViewCourseYear.setText("View report");
        btnViewCourseYear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnViewCourseYearActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnToggleCourseYearLayout = new javax.swing.GroupLayout(pnToggleCourseYear);
        pnToggleCourseYear.setLayout(pnToggleCourseYearLayout);
        pnToggleCourseYearLayout.setHorizontalGroup(
                pnToggleCourseYearLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGap(0, 308, Short.MAX_VALUE)
                        .addGroup(pnToggleCourseYearLayout.createSequentialGroup()
                                .addGroup(pnToggleCourseYearLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(pnToggleCourseYearLayout.createSequentialGroup()
                                                .addContainerGap()
                                                .addComponent(jLabel14))
                                        .addGroup(pnToggleCourseYearLayout.createSequentialGroup()
                                                .addGap(47, 47, 47)
                                                .addComponent(cboCourseYearReport, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(btnViewCourseYear)))
                                .addContainerGap(51, Short.MAX_VALUE))
        );
        pnToggleCourseYearLayout.setVerticalGroup(
                pnToggleCourseYearLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGap(0, 103, Short.MAX_VALUE)
                        .addGroup(pnToggleCourseYearLayout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel14)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(pnToggleCourseYearLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(cboCourseYearReport, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(btnViewCourseYear))
                                .addContainerGap(49, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout pnReportLayout = new javax.swing.GroupLayout(pnReport);
        pnReport.setLayout(pnReportLayout);
        pnReportLayout.setHorizontalGroup(
                pnReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnReportLayout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(pnReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel11)
                                        .addGroup(pnReportLayout.createSequentialGroup()
                                                .addGap(10, 10, 10)
                                                .addGroup(pnReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                        .addComponent(btnToggleClass)
                                                        .addComponent(btnToggleCourse)
                                                        .addComponent(pnToggleClass, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                        .addComponent(pnToggleCourse, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                        .addComponent(btnToggleCourseYear)
                                                        .addComponent(pnToggleCourseYear, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnReportLayout.setVerticalGroup(
                pnReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnReportLayout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnToggleClass)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(pnToggleClass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(btnToggleCourse)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(pnToggleCourse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnToggleCourseYear)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(pnToggleCourseYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(24, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout dlgReportLayout = new javax.swing.GroupLayout(dlgReport.getContentPane());
        dlgReport.getContentPane().setLayout(dlgReportLayout);
        dlgReportLayout.setHorizontalGroup(
                dlgReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(pnReport, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        dlgReportLayout.setVerticalGroup(
                dlgReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(pnReport, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        setBackground(new java.awt.Color(255, 255, 255));

        btnAdd.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/add-16.png"));
        btnAdd.setText("Add");
        btnAdd.setMaximumSize(new java.awt.Dimension(61, 23));
        btnAdd.setMinimumSize(new java.awt.Dimension(61, 23));
        btnAdd.setPreferredSize(new java.awt.Dimension(61, 23));
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });

        btnUpdate.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/update-16.png"));
        btnUpdate.setText("Update");
        btnUpdate.setMaximumSize(new java.awt.Dimension(87, 23));
        btnUpdate.setMinimumSize(new java.awt.Dimension(87, 23));
        btnUpdate.setPreferredSize(new java.awt.Dimension(87, 23));
        btnUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdateActionPerformed(evt);
            }
        });

        btnReport.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/printer-16.png"));
        btnReport.setText("Report");
        btnReport.setMaximumSize(new java.awt.Dimension(71, 23));
        btnReport.setMinimumSize(new java.awt.Dimension(71, 23));
        btnReport.setPreferredSize(new java.awt.Dimension(71, 23));
        btnReport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReportActionPerformed(evt);
            }
        });

        btnRefresh.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/refresh-16.gif"));
        btnRefresh.setText("Refresh");
        btnRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRefreshActionPerformed(evt);
            }
        });

        pnStudentList.setBackground(new java.awt.Color(255, 255, 255));
        pnStudentList.setBorder(javax.swing.BorderFactory.createTitledBorder("Student list"));

        tblStudentList.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][]{

                },
                new String[]{
                        "ID", "Name", "Birthday", "Class", "Description", "Male", "Active"
                }
        ) {
            Class[] types = new Class[]{
                    java.lang.Integer.class, java.lang.String.class, java.util.Date.class, java.lang.Object.class, java.lang.Object.class, java.lang.Boolean.class, java.lang.Boolean.class
            };
            boolean[] canEdit = new boolean[]{
                    false, true, true, true, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        tblStudentList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblStudentListMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tblStudentList);
        tblStudentList.getColumnModel().getColumn(0).setPreferredWidth(30);
        tblStudentList.getColumnModel().getColumn(5).setPreferredWidth(50);
        tblStudentList.getColumnModel().getColumn(6).setPreferredWidth(45);

        javax.swing.GroupLayout pnStudentListLayout = new javax.swing.GroupLayout(pnStudentList);
        pnStudentList.setLayout(pnStudentListLayout);
        pnStudentListLayout.setHorizontalGroup(
                pnStudentListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnStudentListLayout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE)
                                .addContainerGap())
        );
        pnStudentListLayout.setVerticalGroup(
                pnStudentListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnStudentListLayout.createSequentialGroup()
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 393, Short.MAX_VALUE)
                                .addContainerGap())
        );

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 16));
        jLabel4.setForeground(new java.awt.Color(0, 102, 255));
        jLabel4.setText("MANAGE STUDENTS");

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Search for student"));
        jPanel2.setMaximumSize(new java.awt.Dimension(452, 219));
        jPanel2.setMinimumSize(new java.awt.Dimension(452, 219));

        jLabel5.setText("Search by name:");

        btnSearchByName.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/search-16.png"));
        btnSearchByName.setText("Search");
        btnSearchByName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchByNameActionPerformed(evt);
            }
        });

        jLabel6.setText("Advance search");

        btnDropDown.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/dropDown_icon.png"));
        btnDropDown.setBorderPainted(false);
        btnDropDown.setContentAreaFilled(false);
        btnDropDown.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnDropDown.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDropDownActionPerformed(evt);
            }
        });

        pnToggle.setBackground(new java.awt.Color(255, 255, 255));

        btnAdvSearch.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/search-16.png"));
        btnAdvSearch.setText("Search");
        btnAdvSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAdvSearchActionPerformed(evt);
            }
        });

        jLabel7.setText("Student name:");

        jLabel10.setText("Class:");

        javax.swing.GroupLayout pnToggleLayout = new javax.swing.GroupLayout(pnToggle);
        pnToggle.setLayout(pnToggleLayout);
        pnToggleLayout.setHorizontalGroup(
                pnToggleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnToggleLayout.createSequentialGroup()
                                .addGroup(pnToggleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)
                                        .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE))
                                .addGap(18, 18, 18)
                                .addGroup(pnToggleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(cboClassSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(pnToggleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(btnAdvSearch)
                                                .addComponent(txtAdvName, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(90, 90, 90))
        );
        pnToggleLayout.setVerticalGroup(
                pnToggleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnToggleLayout.createSequentialGroup()
                                .addGroup(pnToggleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(txtAdvName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel7))
                                .addGap(18, 18, 18)
                                .addGroup(pnToggleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel10)
                                        .addComponent(cboClassSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btnAdvSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(pnToggle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                                .addComponent(txtSearchByName, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(btnSearchByName))
                                        .addComponent(jLabel5)
                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                                .addComponent(btnDropDown, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jLabel6)))
                                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(txtSearchByName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(btnSearchByName, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(btnDropDown, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
                                        .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(pnToggle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(27, 27, 27))
        );

        pnStudentInfo.setBackground(new java.awt.Color(255, 255, 255));
        pnStudentInfo.setBorder(javax.swing.BorderFactory.createTitledBorder("Add new student"));
        pnStudentInfo.setPreferredSize(new java.awt.Dimension(452, 219));

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText("Name:");
        jLabel2.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jLabel3.setText("Description:");

        txaDescription.setColumns(20);
        txaDescription.setRows(5);
        jScrollPane1.setViewportView(txaDescription);

        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel8.setText("DoB:");

        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel9.setText("Class:");

        jLabel1.setText("Gender:");

        rdoMale.setBackground(new java.awt.Color(255, 255, 255));
        rdoMale.setSelected(true);
        rdoMale.setText("Male");

        rdoFemale.setBackground(new java.awt.Color(255, 255, 255));
        rdoFemale.setText("Female");

        javax.swing.GroupLayout pnStudentInfoLayout = new javax.swing.GroupLayout(pnStudentInfo);
        pnStudentInfo.setLayout(pnStudentInfoLayout);
        pnStudentInfoLayout.setHorizontalGroup(
                pnStudentInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnStudentInfoLayout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(pnStudentInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(pnStudentInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE)
                                        .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(pnStudentInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(pnStudentInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(pnStudentInfoLayout.createSequentialGroup()
                                                        .addComponent(txtName, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                                                        .addGap(184, 184, 184))
                                                .addGroup(pnStudentInfoLayout.createSequentialGroup()
                                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addContainerGap()))
                                        .addGroup(pnStudentInfoLayout.createSequentialGroup()
                                                .addGroup(pnStudentInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(cboMonth, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(cboClass, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(pnStudentInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addGroup(pnStudentInfoLayout.createSequentialGroup()
                                                                .addComponent(jLabel1)
                                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                                .addComponent(rdoMale)
                                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                                .addComponent(rdoFemale))
                                                        .addGroup(pnStudentInfoLayout.createSequentialGroup()
                                                                .addComponent(cboDay, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                .addComponent(cboYear, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                .addGap(19, 19, 19))))
        );
        pnStudentInfoLayout.setVerticalGroup(
                pnStudentInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnStudentInfoLayout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(pnStudentInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel2))
                                .addGap(18, 18, 18)
                                .addGroup(pnStudentInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel3)
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(pnStudentInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel8)
                                        .addComponent(cboMonth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(cboDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(cboYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
                                .addGroup(pnStudentInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel9)
                                        .addComponent(cboClass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel1)
                                        .addComponent(rdoMale)
                                        .addComponent(rdoFemale))
                                .addGap(32, 32, 32))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                                .addContainerGap()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jLabel4)
                                                        .addGroup(layout.createSequentialGroup()
                                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                                        .addComponent(pnStudentInfo, javax.swing.GroupLayout.DEFAULT_SIZE, 427, Short.MAX_VALUE)
                                                                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 427, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                .addComponent(pnStudentList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                        .addGroup(layout.createSequentialGroup()
                                                .addGap(259, 259, 259)
                                                .addComponent(btnAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(btnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(btnRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(btnReport, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addGap(50, 50, 50)
                                .addComponent(jLabel4)
                                .addGap(29, 29, 29)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(pnStudentList, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(layout.createSequentialGroup()
                                                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(pnStudentInfo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(btnAdd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(btnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(btnReport, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(btnRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap(85, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnAddActionPerformed(ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        doAdd();
    }//GEN-LAST:event_btnAddActionPerformed

    private void btnUpdateActionPerformed(ActionEvent evt) {//GEN-FIRST:event_btnUpdateActionPerformed
        doUpdate();
    }//GEN-LAST:event_btnUpdateActionPerformed

    private void btnReportActionPerformed(ActionEvent evt) {//GEN-FIRST:event_btnReportActionPerformed
        dlgReport = new JDialog();
        dlgReport.setContentPane(pnReport);
        dlgReport.setLocationRelativeTo(null);
        dlgReport.pack();
        dlgReport.setVisible(true);
    }//GEN-LAST:event_btnReportActionPerformed

    private void tblStudentListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblStudentListMouseClicked
        btnUpdate.setEnabled(true);
    }//GEN-LAST:event_tblStudentListMouseClicked

    private void btnRefreshActionPerformed(ActionEvent evt) {//GEN-FIRST:event_btnRefreshActionPerformed
        refresh();
    }//GEN-LAST:event_btnRefreshActionPerformed

    private void btnSearchByNameActionPerformed(ActionEvent evt) {//GEN-FIRST:event_btnSearchByNameActionPerformed
        nameSearch();
    }//GEN-LAST:event_btnSearchByNameActionPerformed

    private void btnDropDownActionPerformed(ActionEvent evt) {//GEN-FIRST:event_btnDropDownActionPerformed
        Helper.toggle(pnToggle);
    }//GEN-LAST:event_btnDropDownActionPerformed

    private void btnAdvSearchActionPerformed(ActionEvent evt) {//GEN-FIRST:event_btnAdvSearchActionPerformed
        advanceSearch();
    }//GEN-LAST:event_btnAdvSearchActionPerformed

    private void btnToggleClassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnToggleClassActionPerformed
        Helper.toggle(pnToggleClass);
    }//GEN-LAST:event_btnToggleClassActionPerformed

    private void btnViewClassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnViewClassActionPerformed
        int classId = allClasses.get(cboClassReport.getSelectedIndex()).getId();
        StudentReporter sr = new StudentReporter();
        sr.hasClassId(classId);
        try {
            sr.view();
        } catch (JRException ex) {
            logger.log(Level.SEVERE, null, ex);
            statusBar.setMessage("Unable to view report.", StatusBar.ERROR_TYPE);
        } catch (SQLException ex) {
            logger.log(Level.SEVERE, null, ex);
            statusBar.setMessage("Unable to connect to server.", StatusBar.ERROR_TYPE);
        }
    }//GEN-LAST:event_btnViewClassActionPerformed

    private void btnToggleCourseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnToggleCourseActionPerformed
        Helper.toggle(pnToggleCourse);
    }//GEN-LAST:event_btnToggleCourseActionPerformed

    private void btnViewCourseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnViewCourseActionPerformed
        int courseId = allCourses.get(cboCourseReport.getSelectedIndex()).getId();
        StudentReporter sr = new StudentReporter();
        sr.hasCourseId(courseId);
        try {
            sr.view();
        } catch (JRException ex) {
            logger.log(Level.SEVERE, null, ex);
            statusBar.setMessage("Unable to view report.", StatusBar.ERROR_TYPE);
        } catch (SQLException ex) {
            logger.log(Level.SEVERE, null, ex);
            statusBar.setMessage("Unable to connect to server.", StatusBar.ERROR_TYPE);
        }
    }//GEN-LAST:event_btnViewCourseActionPerformed

    private void btnToggleCourseYearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnToggleCourseYearActionPerformed
        Helper.toggle(pnToggleCourseYear);
    }//GEN-LAST:event_btnToggleCourseYearActionPerformed

    private void btnViewCourseYearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnViewCourseYearActionPerformed
        int courseYearId = allCourseYears.get(cboCourseYearReport.getSelectedIndex()).getId();
        StudentReporter sr = new StudentReporter();
        sr.hasCourseYearId(courseYearId);
        try {
            sr.view();
        } catch (JRException ex) {
            logger.log(Level.SEVERE, null, ex);
            statusBar.setMessage("Unable to view report.", StatusBar.ERROR_TYPE);
        } catch (SQLException ex) {
            logger.log(Level.SEVERE, null, ex);
            statusBar.setMessage("Unable to connect to server.", StatusBar.ERROR_TYPE);
        }
    }//GEN-LAST:event_btnViewCourseYearActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnAdvSearch;
    private javax.swing.JButton btnDropDown;
    private javax.swing.JButton btnRefresh;
    private javax.swing.JButton btnReport;
    private javax.swing.JButton btnSearchByName;
    private javax.swing.JButton btnToggleClass;
    private javax.swing.JButton btnToggleCourse;
    private javax.swing.JButton btnToggleCourseYear;
    private javax.swing.JButton btnUpdate;
    private javax.swing.JButton btnViewClass;
    private javax.swing.JButton btnViewCourse;
    private javax.swing.JButton btnViewCourseYear;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox cboClass;
    private javax.swing.JComboBox cboClassReport;
    private javax.swing.JComboBox cboClassSearch;
    private javax.swing.JComboBox cboCourseReport;
    private javax.swing.JComboBox cboCourseYearReport;
    private javax.swing.JComboBox cboDay;
    private javax.swing.JComboBox cboMonth;
    private javax.swing.JComboBox cboYear;
    private javax.swing.JDialog dlgReport;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPanel pnReport;
    private javax.swing.JPanel pnStudentInfo;
    private javax.swing.JPanel pnStudentList;
    private javax.swing.JPanel pnToggle;
    private javax.swing.JPanel pnToggleClass;
    private javax.swing.JPanel pnToggleCourse;
    private javax.swing.JPanel pnToggleCourseYear;
    private javax.swing.JRadioButton rdoFemale;
    private javax.swing.JRadioButton rdoMale;
    private javax.swing.JTable tblStudentList;
    private javax.swing.JTextArea txaDescription;
    private javax.swing.JTextField txtAdvName;
    private javax.swing.JTextField txtName;
    private javax.swing.JTextField txtSearchByName;
    // End of variables declaration//GEN-END:variables

}
